|
1
|
|
|
/** |
|
2
|
|
|
* A module for player. |
|
3
|
|
|
* |
|
4
|
|
|
* @module |
|
5
|
|
|
*/ |
|
6
|
|
|
"use strict"; |
|
7
|
|
|
|
|
8
|
|
|
class Gameboard { |
|
9
|
|
|
/** |
|
10
|
|
|
* @constructor |
|
11
|
|
|
* |
|
12
|
|
|
* @param {int} width - number of cards horizontaly. |
|
13
|
|
|
* @param {int} height - number of cards verticaly. |
|
14
|
|
|
*/ |
|
15
|
|
|
constructor(width, height) { |
|
16
|
|
|
this.width = width; |
|
17
|
|
|
this.height = height; |
|
18
|
|
|
this.numOfCards = width*height; |
|
19
|
|
|
this.position = []; // of cards that has flipped |
|
20
|
|
|
this.cardvalue = []; // of cards that has flipped |
|
21
|
|
|
this.activeplayer; // nickname of player who´s turn it is |
|
|
|
|
|
|
22
|
|
|
this.gotpair; |
|
|
|
|
|
|
23
|
|
|
this.pairpositions = []; |
|
24
|
|
|
this.pairvalues = []; |
|
25
|
|
|
this.paircolors = []; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
getWidth() { |
|
29
|
|
|
return this.width; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
getHeight() { |
|
33
|
|
|
return this.height; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
setWidth(width) { |
|
37
|
|
|
this.width = width; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
setHeight(height) { |
|
41
|
|
|
this.height = height; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
setGotPair(gotpair) { |
|
45
|
|
|
this.gotpair = gotpair; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
addPosition(position) { |
|
49
|
|
|
this.position.push(position); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
addCardValue(cardvalue) { |
|
53
|
|
|
this.cardvalue.push(cardvalue); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
addPairPositions(pairpos) { |
|
57
|
|
|
this.pairpositions.push.apply(this.pairpositions, pairpos); |
|
58
|
|
|
// console.log("GAMEBOARD: addPairPositions: " + this.pairpositions); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
addPairValues(cardvalue) { |
|
62
|
|
|
this.pairvalues.push(cardvalue); |
|
63
|
|
|
this.pairvalues.push(cardvalue); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
addPairColors(colorclass) { |
|
67
|
|
|
this.paircolors.push(colorclass); |
|
68
|
|
|
this.paircolors.push(colorclass); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Flips all cards back |
|
73
|
|
|
*/ |
|
74
|
|
|
resetCards() { |
|
75
|
|
|
var pairpositions = this.pairpositions; |
|
76
|
|
|
var pairvalues = this.pairvalues; |
|
77
|
|
|
|
|
78
|
|
|
this.position = []; |
|
79
|
|
|
this.position.push.apply(this.position, pairpositions); |
|
80
|
|
|
this.cardvalue = []; |
|
81
|
|
|
this.cardvalue.push.apply(this.cardvalue, pairvalues); |
|
82
|
|
|
// console.log("GAMEBOARD: resetCards - this.position: " + this.position); |
|
83
|
|
|
// console.log("GAMEBOARD: resetCards - this.pairpositions: " + this.pairpositions); |
|
84
|
|
|
// console.log("GAMEBOARD: resetCards - this.cardvalue: " + this.cardvalue); |
|
85
|
|
|
// console.log("GAMEBOARD: resetCards - this.pairpositions: " + this.pairpositions); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
setActivePlayer(player) { |
|
89
|
|
|
this.activeplayer = player; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
// Export module |
|
94
|
|
|
module.exports = Gameboard; |
|
95
|
|
|
|